﻿#pragma once

#include <QWidget>
#include "ui_H264OrH265FilePlayByEncapsulationWindow.h"
#include <QCloseEvent>
#include "../../../common/utils/BinaryFileReader.h"
#include "../../sdl/render/IVideoRenderView.h"
#include "../codec/YDecoder.h"
#include <iostream>
#include <thread>

class H264OrH265FilePlayByEncapsulationWindow : public QWidget
{
	Q_OBJECT

public:
	H264OrH265FilePlayByEncapsulationWindow(QWidget *parent = nullptr);
	~H264OrH265FilePlayByEncapsulationWindow();
	void Draw();
	void Release();

protected:
	// 重写关闭事件处理函数
	void closeEvent(QCloseEvent* event) override;

public slots:
	void onVideoFormatChanged(int pos);
	void onCodecFormatChanged(int pos);
	void onSelectedFile();
	void onStartPlayVideo();
private:
	Ui::H264OrH265FilePlayByEncapsulationWindow ui;
	int codecId = 0;
	BinaryFileReader* reader = nullptr;
	IVideoRenderView* renderView = nullptr;
	QString fileName;
	std::unique_ptr<std::thread> renderThread;
	bool isRunning = true;
	unsigned char inbuf[4096] = { 0 };
	int videoWidth = 1920;
	int videoHeight = 1080;
	bool isHwCodec = false;
};
